package com.bit.demo1;

//***********************继承****************************************
//继承一般不要超过三层，不想被继承的话用final
//父类、基类、超类
class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println("eat()");
    }
}

//extends：继承   java当中是单继承，不能同时继承多个父类
class Dog extends Animal {//子类、派生类

    public Dog(String name, int age) {
        super(name, age);//子类创建 构造方法时，要先给父类创建构造方法，再使用super时不会报错
    }
}


class Bird extends Animal {
    public String wing;

    public Bird(String name,int age,String wing){
        super(name,age);
        this.wing = wing;
    }

    public void fly() {
        System.out.println(name + "fly()");
    }
}




public class TestDemo {
    public static void main2(String[] args) {
        Animal animal = new Dog("haha",18);//父类引用  引用子类对象
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("haha",19);
        System.out.println(dog.name);
        dog.eat();
    }

//***********向下转型  要判定一个引用是否是某个类的实例
    public static void main(String[] args) {
        Animal animal2 = new Dog("haha",19);
        if (animal2 instanceof Bird){
            Bird bird = (Bird) animal2;
            bird.fly();
        }
    }
}
